##### CHECK CIRCULARITY OF SALIENCE WITH LEADS AND LAGS #####
library(haven)
library(lme4)
library(texreg)
library(sjPlot)
library(sjstats)
library(fixest)
library(ggplot2)
library(ggeffects)
library(tidyverse)
### LOAD DATA

load("Data/EP_debates_07062023.Rdata")

### Read in Data from 
eurobar <- read_dta("Data/eurobarmeter_challengers_2023.dta") ## Wratil (forthcoming) - dataset will be added upon publication by Wratil

# Prep Data for Merging ###

eurobar$date_char <- as.character(eurobar$start_date)
eurobar$date_char <- str_sub(eurobar$date_char, 6, -4)
eurobar$date_char <- as.numeric(eurobar$date_char)
eurobar$sem <- ifelse(eurobar$date_char <=6, 1, 2)
eurobar$date_char <- as.character(eurobar$date_char)
eurobar$year <- as.character(eurobar$year)

eurobar <- mutate(eurobar,
                  country = case_when(nation == "at" ~ "Austria",
                                      nation == "be" ~ "Belgium",
                                      nation == "bu" ~ "Bulgaria",
                                      nation == "cy" ~ "Cyprus",
                                      nation == "cz" ~ "Czech Republic",
                                      nation == "de" ~ "Germany",
                                      nation == "dk" ~ "Denmark",
                                      nation == "ee" ~ "Estonia",
                                      nation == "el" ~ "Greece",
                                      nation == "es" ~ "Spain",
                                      nation == "fi" ~ "Finland",
                                      nation == "fr" ~ "France",
                                      nation == "hr" ~ "Croatia",
                                      nation == "hu" ~ "Hungary",
                                      nation == "ie" ~ "Ireland",
                                      nation == "it" ~ "Italy",
                                      nation == "lt" ~ "Lithuania",
                                      nation == "lv" ~ "Latvia",
                                      nation == "mt" ~ "Malta",
                                      nation == "nl" ~ "Netherlands",
                                      nation == "pl" ~ "Poland",
                                      nation == "pt" ~ "Portugal",
                                      nation == "ro" ~ "Romania",
                                      nation == "se" ~ "Sweden",
                                      nation == "si" ~ "Slovenia",
                                      nation == "sk" ~ "Slovakia",
                                      nation == "uk" ~ "United Kingdom"))
attr(eurobar$start_date, "ATT") <- NULL
eurobar$date <- eurobar$start_date
range(eurobar$date)
range(df_complete$date)
levels(df_complete$country)
eurobar$country <- as.character(eurobar$country)
eurobar$country


#### Create lags for Salience Measures ###

eurobar_lagged <- eurobar %>%
  group_by(country) %>%
  mutate(immi_lead15 = lead(mip_n_immigration_ipol, n = 15),
         immi_lead30 = lead(mip_n_immigration_ipol, n = 30),
         immi_lead60 = lead(mip_n_immigration_ipol, n = 60),
         immi_lead90 = lead(mip_n_immigration_ipol, n = 90),
         immi_lead180 =lead(mip_n_immigration_ipol, n = 180),
         aut_lead15 =  lead(mip_n_govdebt_ipol, n = 15),
         aut_lead30 =  lead(mip_n_govdebt_ipol, n = 30),
         aut_lead60 =  lead(mip_n_govdebt_ipol, n = 60),
         aut_lead90 =  lead(mip_n_govdebt_ipol, n = 90),
         aut_lead180 = lead(mip_n_govdebt_ipol, n = 180))

eurobar_lagged <- eurobar_lagged[,c(1,26:36)]

EP_eurobar <- left_join(EP_debates, eurobar_lagged, by = c("date", "country"))


EP_eurobar$radical <- abs(EP_eurobar$lrgen - 5)
range(EP_eurobar$radical, na.rm = TRUE)

centFUN <- function(x) {
  x - mean(x, na.rm = TRUE)
}

result <- apply(EP_eurobar[,c(22:24, 27:71, 73:75, 77:107,117:118)], MARGIN = 2, FUN = centFUN)
result <- as.data.frame(result)


EP_eurobar_cent <- cbind(EP_eurobar[,-c(22:24, 27:71, 73:75, 77:107,117:118)], result)

rm(list=setdiff(ls(), "EP_eurobar_cent"))

EP_eurobar_cent$embed_dict_scale <- scale(EP_eurobar_cent$embed_dict)
EP_eurobar_cent$aut_dict_scale <- scale(EP_eurobar_cent$aut_dict)
EP_eurobar_cent$immi_dict_scale <- scale(EP_eurobar_cent$immi_dict)
EP_eurobar_cent$int_dict_scale <- scale(EP_eurobar_cent$int_dict)
EP_eurobar_cent$lrgen_scale <- scale(EP_eurobar_cent$lrgen)
EP_eurobar_cent$radical_scale <- scale(EP_eurobar_cent$radical)

EP_eurobar_cent$aut_sal <- scale(EP_eurobar_cent$mip_n_govdebt_ipol)
EP_eurobar_cent$immi_sal <- scale(EP_eurobar_cent$mip_n_immigration_ipol)
EP_eurobar_cent$int_po <- scale(EP_eurobar_cent$eum_ipol)

EP_eurobar_cent$immi_lead15     <- scale(EP_eurobar_cent$immi_lead15)
EP_eurobar_cent$immi_lead30     <- scale( EP_eurobar_cent$immi_lead30)
EP_eurobar_cent$immi_lead60     <- scale( EP_eurobar_cent$immi_lead60 )
EP_eurobar_cent$immi_lead90     <- scale(EP_eurobar_cent$immi_lead90 )
EP_eurobar_cent$immi_lead180    <- scale(EP_eurobar_cent$immi_lead180 )

EP_eurobar_cent$immi_lag15      <- scale(EP_eurobar_cent$immi_lag15)
EP_eurobar_cent$immi_lag30      <- scale(EP_eurobar_cent$immi_lag30)
EP_eurobar_cent$immi_lag60      <- scale(EP_eurobar_cent$immi_lag60)
EP_eurobar_cent$immi_lag90      <- scale(EP_eurobar_cent$immi_lag90)
EP_eurobar_cent$immi_lag180     <- scale(EP_eurobar_cent$immi_lag180)

EP_eurobar_cent$aut_lead15     <- scale(EP_eurobar_cent$aut_lead15)
EP_eurobar_cent$aut_lead30     <- scale( EP_eurobar_cent$aut_lead30)
EP_eurobar_cent$aut_lead60     <- scale( EP_eurobar_cent$aut_lead60 )
EP_eurobar_cent$aut_lead90     <- scale(EP_eurobar_cent$aut_lead90 )
EP_eurobar_cent$aut_lead180    <- scale(EP_eurobar_cent$aut_lead180 )

EP_eurobar_cent$aut_lag15      <- scale(EP_eurobar_cent$aut_lag15)
EP_eurobar_cent$aut_lag30      <- scale(EP_eurobar_cent$aut_lag30)
EP_eurobar_cent$aut_lag60      <- scale(EP_eurobar_cent$aut_lag60)
EP_eurobar_cent$aut_lag90      <- scale(EP_eurobar_cent$aut_lag90)
EP_eurobar_cent$aut_lag180     <- scale(EP_eurobar_cent$aut_lag180)

EP_eurobar_cent$year <- as.factor(EP_eurobar_cent$year)
#### AUSTERITY models with LAGS and LEADS

AUT_sal_model_lag15 <- lmer(aut_dict_scale ~ challenge*aut_lag15 + EP_Coa + nat_opp +lrgen_scale  + de_macro + de_civil + de_health + 
                              de_agri + de_labour + de_edu + de_envi + de_energy + 
                              de_immi + de_transport + de_law + de_welfare  + de_commerce +
                              de_defense + de_techno + de_trade + de_intern + de_govern +
                              de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                              (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lag15)


AUT_sal_model_lag30 <- lmer(aut_dict_scale ~ challenge*aut_lag30 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                              de_agri + de_labour + de_edu + de_envi + de_energy + 
                              de_immi + de_transport + de_law + de_welfare  + de_commerce +
                              de_defense + de_techno + de_trade + de_intern + de_govern +
                              de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                              (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lag30)

AUT_sal_model_lag60 <- lmer(aut_dict_scale ~ challenge*aut_lag60 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                              de_agri + de_labour + de_edu + de_envi + de_energy + 
                              de_immi + de_transport + de_law + de_welfare  + de_commerce +
                              de_defense + de_techno + de_trade + de_intern + de_govern +
                              de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                              (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lag60)


AUT_sal_model_lag90 <- lmer(aut_dict_scale ~ challenge*aut_lag90 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                              de_agri + de_labour + de_edu + de_envi + de_energy + 
                              de_immi + de_transport + de_law + de_welfare  + de_commerce +
                              de_defense + de_techno + de_trade + de_intern + de_govern +
                              de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                              (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lag90)

AUT_sal_model_lag180 <- lmer(aut_dict_scale ~ challenge*aut_lag180 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                              de_agri + de_labour + de_edu + de_envi + de_energy + 
                              de_immi + de_transport + de_law + de_welfare  + de_commerce +
                              de_defense + de_techno + de_trade + de_intern + de_govern +
                              de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                              (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lag180)

####

AUT_sal_model_lead15 <- lmer(aut_dict_scale ~ challenge*aut_lead15 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                              de_agri + de_labour + de_edu + de_envi + de_energy + 
                              de_immi + de_transport + de_law + de_welfare  + de_commerce +
                              de_defense + de_techno + de_trade + de_intern + de_govern +
                              de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                              (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lead15)


AUT_sal_model_lead30 <- lmer(aut_dict_scale ~ challenge*aut_lead30 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                              de_agri + de_labour + de_edu + de_envi + de_energy + 
                              de_immi + de_transport + de_law + de_welfare  + de_commerce +
                              de_defense + de_techno + de_trade + de_intern + de_govern +
                              de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                              (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lead30)

AUT_sal_model_lead60 <- lmer(aut_dict_scale ~ challenge*aut_lead60 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                              de_agri + de_labour + de_edu + de_envi + de_energy + 
                              de_immi + de_transport + de_law + de_welfare  + de_commerce +
                              de_defense + de_techno + de_trade + de_intern + de_govern +
                              de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                              (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lead60)

AUT_sal_model_lead90 <- lmer(aut_dict_scale ~ challenge*aut_lead90 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lead90)

AUT_sal_model_lead180 <- lmer(aut_dict_scale ~ challenge*aut_lead180 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(AUT_sal_model_lead180)




texreg(list(AUT_sal_model_lead15, AUT_sal_model_lead30, AUT_sal_model_lead60, AUT_sal_model_lead90, AUT_sal_model_lead180),
       file = "Tables/aut_sal_leads_080623.tex",
       include.ci = FALSE,
       custom.coef.map = list("challenge" = "Challenger",
                              "aut_lead15" = "Austerity (Lead 15)",
                              "aut_lead30" = "Austerity (Lead 30)",
                              "aut_lead60" = "Austerity (Lead 60)",
                              "aut_lead90" = "Austerity (Lead 90)",
                              "aut_lead180" = "Austerity (Lead 180)",
                              "challenge:aut_lead15" = "Challenge * Austerity (Lead 15)",
                              "challenge:aut_lead30" = "Challenge * Austerity (Lead 30)",
                              "challenge:aut_lead60" = "Challenge * Austerity (Lead 60)",
                              "challenge:aut_lead90" = "Challenge * Austerity (Lead 90)",
                              "challenge:aut_lead180" ="Challenge * Austerity (Lead 180)",
                              "lrgen_scale" = "LR-Position",
                              "EP_Coa" = "EP-Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "Yes", "Yes", "Yes", "Yes"),
                              "Year Fixed Effects" = c("Yes", "Yes", "Yes", "Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes", "Yes", "Yes", "Yes")),
       custom.model.names = c("Austerity", "Austerity", "Austerity", "Austerity", "Austerity"),
       custom.note = "%stars. Random Intercepts for Parties and MEPs",
       digits = 3,
       label = "The effect of changes in salience of Austerity (leads in days)")



texreg(list(AUT_sal_model_lag15, AUT_sal_model_lag30, AUT_sal_model_lag60, AUT_sal_model_lag90, AUT_sal_model_lag180),
       file = "Tables/aut_sal_lags_080623.tex",
       include.ci = FALSE,
       custom.coef.map = list("challenge" = "Challenger",
                              "aut_lag15" = "Austerity (Lag 15)",
                              "aut_lag30" = "Austerity (Lag 30)",
                              "aut_lag60" = "Austerity (Lag 60)",
                              "aut_lag90" = "Austerity (Lag 90)",
                              "aut_lag180" ="Austerity (Lag 180)",
                              "challenge:aut_lag15" = "Challenge * Austerity (Lag 15)",
                              "challenge:aut_lag30" = "Challenge * Austerity (Lag 30)",
                              "challenge:aut_lag60" = "Challenge * Austerity (Lag 60)",
                              "challenge:aut_lag90" = "Challenge * Austerity (Lag 90)",
                              "challenge:aut_lag180" ="Challenge * Austerity (Lag 180)",
                              "lrgen_scale" = "LR-Position",
                              "EP_Coa" = "EP Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "Yes", "Yes", "Yes", "Yes"),
                              "Year Fixed Effects" = c("Yes", "Yes", "Yes", "Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes", "Yes", "Yes", "Yes")),
       custom.model.names = c("Austerity", "Austerity", "Austerity", "Austerity", "Austerity"),
       custom.note = "%stars. Random Intercepts for Parties and MEPs",
       digits = 3,
       label = "The effect of changes in salience of Austerity (lags in days)")





#### IMMIGRATION models with lags

Immi_sal_model_lag15 <- lmer(immi_dict_scale ~ challenge*immi_lag15 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lag15)


Immi_sal_model_lag30 <- lmer(immi_dict_scale ~ challenge*immi_lag30 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lag30)

Immi_sal_model_lag60 <- lmer(immi_dict_scale ~ challenge*immi_lag60 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lag60)

Immi_sal_model_lag90 <- lmer(immi_dict_scale ~ challenge*immi_lag90  + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lag90)

Immi_sal_model_lag180 <- lmer(immi_dict_scale ~ challenge*immi_lag180 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lag180)

######

Immi_sal_model_lead15 <- lmer(immi_dict_scale ~ challenge*immi_lead15 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lead15)


Immi_sal_model_lead30 <- lmer(immi_dict_scale ~ challenge*immi_lead30 + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lead30)

Immi_sal_model_lead60 <- lmer(immi_dict_scale ~ challenge*immi_lead60  + EP_Coa +  nat_opp +lrgen_scale  + de_macro + de_civil + de_health + 
                               de_agri + de_labour + de_edu + de_envi + de_energy + 
                               de_immi + de_transport + de_law + de_welfare  + de_commerce +
                               de_defense + de_techno + de_trade + de_intern + de_govern +
                               de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                               (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lead60)

Immi_sal_model_lead90 <- lmer(immi_dict_scale ~ challenge*immi_lead90  + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                                de_agri + de_labour + de_edu + de_envi + de_energy + 
                                de_immi + de_transport + de_law + de_welfare  + de_commerce +
                                de_defense + de_techno + de_trade + de_intern + de_govern +
                                de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                                (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lead90)

Immi_sal_model_lead180 <- lmer(immi_dict_scale ~ challenge*immi_lead180  + EP_Coa + nat_opp + lrgen_scale  + de_macro + de_civil + de_health + 
                                de_agri + de_labour + de_edu + de_envi + de_energy + 
                                de_immi + de_transport + de_law + de_welfare  + de_commerce +
                                de_defense + de_techno + de_trade + de_intern + de_govern +
                                de_lands + de_culture + proced_1 + proced_2 + proced_3 +proced_4 + proced_5+ year + as.factor(country) +
                                (1|mep_ids) + (1|party_id), data = EP_eurobar_cent, control = lmerControl(optimizer = "Nelder_Mead"))

texreg(Immi_sal_model_lead180)

texreg(list(Immi_sal_model_lead15, Immi_sal_model_lead30, Immi_sal_model_lead60, Immi_sal_model_lead90, Immi_sal_model_lead180),
       file = "Tables/Immi_sal_leads_080623.tex",
       include.ci = FALSE,
       custom.coef.map = list("challenge" = "Challenger",
                              "immi_lead15" = "Immigration (Lead 15)",
                              "immi_lead30" = "Immigration (Lead 30)",
                              "immi_lead60" = "Immigration (Lead 60)",
                              "immi_lead90" = "Immigration (Lead 90)",
                              "immi_lead180" = "Immigration (Lead 180)",
                              "challenge:immi_lead15" = "Challenge * Immigration (Lead 15)",
                              "challenge:immi_lead30" = "Challenge * Immigration (Lead 30)",
                              "challenge:immi_lead60" = "Challenge * Immigration (Lead 60)",
                              "challenge:immi_lead90" = "Challenge * Immigration (Lead 90)",
                              "challenge:immi_lead180" ="Challenge * Immigration (Lead 180)",
                              "lrgen_scale" = "LR-Position",
                              "EP_Coa" = "EP Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "Yes", "Yes", "Yes", "Yes"),
                              "Year Fixed Effects" = c("Yes", "Yes", "Yes", "Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes", "Yes", "Yes", "Yes")),
       custom.model.names = c("Immigration", "Immigration", "Immigration", "Immigration", "Immigration"),
       custom.note = "%stars. Random Intercepts for Parties and MEPs",
       digits = 3,
       label = "The effect of changes in salience of Immigration (leads in days)")

texreg(list(Immi_sal_model_lag15, Immi_sal_model_lag30, Immi_sal_model_lag60, Immi_sal_model_lag90, Immi_sal_model_lag180),
       file = "Tables/Immi_sal_lags_80623.tex",
       include.ci = FALSE,
       custom.coef.map = list("challenge" = "Challenger",
                              "immi_lag15" = "Immigration (Lag 15)",
                              "immi_lag30" = "Immigration (Lag 30)",
                              "immi_lag60" = "Immigration (Lag 60)",
                              "immi_lag90" = "Immigration (Lag 90)",
                              "immi_lag180" ="Immigration (Lag 180)",
                              "challenge:immi_lag15" = "Challenge * Immigration (Lag 15)",
                              "challenge:immi_lag30" = "Challenge * Immigration (Lag 30)",
                              "challenge:immi_lag60" = "Challenge * Immigration (Lag 60)",
                              "challenge:immi_lag90" = "Challenge * Immigration (Lag 90)",
                              "challenge:immi_lag180" ="Challenge * Immigration (Lag 180)",
                              "lrgen_scale" = "LR-Position",
                              "EP_Coa" = "EP-Opposition",
                              "nat_opp" = "Nat. Opposition"),
       booktabs = TRUE,
       dcolumn = FALSE,
       custom.gof.rows = list("Topic Controls" = c("Yes", "Yes", "Yes", "Yes", "Yes"),
                              "Year Fixed Effects" = c("Yes", "Yes", "Yes", "Yes", "Yes"),
                              "Country Fixed Effects" = c("Yes", "Yes", "Yes", "Yes", "Yes")),
       custom.model.names = c("Immigration", "Immigration", "Immigration", "Immigration", "Immigration"),
       custom.note = "%stars. Random Intercepts for Parties and MEPs",
       digits = 3,
       label = "The effect of changes in salience of Immigration (lags in days)")




